import { useState } from 'react';

interface ModalState {
  isOpenRelease: boolean;
  isOpenDelete: boolean;
  isOpenEdit: boolean;
}

const useModalState = () => {
  const [modalState, setModalState] = useState<ModalState>({
    isOpenRelease: false,
    isOpenDelete: false,
    isOpenEdit: false,
  });

  const closeModal = () => {
    setModalState({
      isOpenRelease: false,
      isOpenDelete: false,
      isOpenEdit: false,
    });
  };

  const openModal = (modalType: string) => {
    const type = modalType.charAt(0).toUpperCase() + modalType.slice(1);
    const isTypeKey = `isOpen${type}`;
    setModalState({
      ...modalState,
      [isTypeKey]: true,
    });
  };

  const { isOpenRelease, isOpenDelete, isOpenEdit } = modalState;

  return { openModal, closeModal, isOpenRelease, isOpenDelete, isOpenEdit };
};

export default useModalState;
